<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>内容生成器</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
        }

        /* 遮罩层 */
        .overlay {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
            z-index: 1;
        }

        /* 弹窗样式 */
        .modal {
            display: none;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: #fff;
            padding: 20px;
            box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
            z-index: 2;
            width: 300px;
            text-align: center;
            border-radius: 10px;
        }

        /* 关闭按钮 */
        .close-btn {
            background-color: #f44336;
            color: white;
            border: none;
            padding: 5px 10px;
            cursor: pointer;
            border-radius: 5px;
            margin-top: 10px;
        }

        .close-btn:hover {
            background-color: #d32f2f;
        }

        body {
            padding: 20px;
            background: #fff;
            display: flex;
            gap: 20px;
        }

        .left-panel {
            width: 300px;
            flex-shrink: 0;
        }

        .app-grid {
            display: grid;
            grid-template-columns: repeat(2, 100px);
            gap: 15px;
            margin-bottom: 20px;
        }

        .app-item {
            text-align: center;
            cursor: pointer;
        }

        .app-icon {
            width: 100px;
            height: 100px;
            border-radius: 20px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 8px;
            background: #f2f2fd;
            transition: all 0.3s;
        }

        .app-icon.active {
            background: #5048e5; 
        }

        .app-icon.active img {
            /* filter: brightness(0) invert(1); */
        }

        .app-name {
            font-size: 14px;
            color: #333;
        }

        .input-section {
            margin-top: 30px;
        }

        .input-label {
            font-size: 14px;
            color: #333;
            margin-bottom: 10px;
        }

        textarea {
            width: 90%;
            height: 150px;
            padding: 12px;
            border: 1px solid #d9d9d9;
            border-radius: 8px;
            resize: none;
            font-size: 14px;
            margin-bottom: 20px;
        }

        textarea:focus {
            outline: none;
            border-color: #1890ff; 
            box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
        }

        .generate-btn {
            background: #5048e5;
            color: white;
            border: none;
            padding: 8px 24px;
            border-radius: 6px;
            font-size: 14px;
            cursor: pointer;
            transition: background 0.3s;
        }

        .generate-btn:hover {
            background: #817bec;
        }

        .right-panel {
            flex: 1;
            background: linear-gradient(to right, #eef0fd, #ece8fe);
            border-radius: 12px;
            padding: 20px;
            min-height: 500px;
        }

        .content-paragraph {
            margin-bottom: 15px;
            line-height: 1.8;
            font-size: 14px;
        }

        .hashtags {
            margin-top: 20px;
            color: #1890ff; 
            font-size: 14px;
            line-height: 1.6;
        }
    </style>
    <script src="qrc:///qtwebchannel/qwebchannel.js"></script>
</head>
<body>
<div id="overlay" class="overlay" onclick="closeModal()"></div>

<div id="modal" class="modal">
    <p id="message">消息弹窗</p>
    <!-- TODO: 调整消息弹窗样式 -->
    <button class="close-btn" onclick="closeModal()">关闭</button>
</div>
<div class="left-panel">
    <div class="app-grid">
        <div class="app-item">
            <div class="app-icon xiaohongshu">
                <img src="../../images/小红书.svg" alt="xhs" style="width: 40px; height: 40px;">
            </div>
            <div class="app-name">小红书</div>
        </div>
        <div class="app-item">
            <div class="app-icon short-video">
                <img src="../../images/抖音.svg" alt="shot" style="width: 40px; height: 40px;">
            </div>
            <div class="app-name">短视频</div>
        </div>
        <div class="app-item">
            <div class="app-icon official-account">
                <img src="../../images/公众号.svg" alt="wechat" style="width: 40px; height: 40px;">
            </div>
            <div class="app-name">公众号</div>
        </div>
        <div class="app-item">
            <div class="app-icon moments">
                <img src="../../images/朋友圈.svg" alt="moments" style="width: 40px; height: 40px;">
            </div>
            <div class="app-name">朋友圈</div>
        </div>
    </div>

    <div class="input-section">
        <div class="input-label">请输入文案描述:</div>
        <label for="inputText"></label><textarea id="inputText" placeholder="请输入内容描述"></textarea>
        <button class="generate-btn" onclick="generateContent()">立即生成</button>
    </div>
</div>

<div class="right-panel" id="outputContent">
    <!-- Generated content will appear here -->
</div>

<script type="text/javascript">
    document.addEventListener('DOMContentLoaded', function () {
        let platform = "xhs";
        new QWebChannel(parent.qt.webChannelTransport, function (channel) {
            Bridge = channel.objects.Bridge;

            Bridge.started.connect(function (msg) {
                showModal(msg)
            });
            Bridge.finished.connect(function (msg) {
                showModal(msg)
            });
            Bridge.failed.connect(function (msg) {
                showModal(msg)
            });
            Bridge.result.connect(function (content) {
                // TODO: 显示结果标题
            })

            window.generateContent = function () {
                let desc = document.getElementById("inputText").value;
                if (!desc || desc.trim() === '') {
                    showModal("请输入内容");
                    return;
                }
                Bridge.general_write(platform, "content", desc);
            }
        });

        // 获取所有app图标和结果标题
        const appIcons = document.querySelectorAll('.app-icon');

        // 为每个图标添加点击事件
        appIcons.forEach(icon => {
            icon.addEventListener('click', () => {
                // 移除所有图标的active类
                appIcons.forEach(i => i.classList.remove('active'));
                // 给当前点击的图标添加active类
                icon.classList.add('active');
                // 更新结果标题
                platform = icon.querySelector('img').alt;
                alert(platform)
            });
        });

        // 默认选中小红书
        document.querySelector('.app-icon').classList.add('active');
        window.showModal = function (message) {
            document.getElementById("message").innerText = message;
            document.getElementById("overlay").style.display = "block";
            document.getElementById("modal").style.display = "block";
        };

        window.closeModal = function () {
            document.getElementById("overlay").style.display = "none";
            document.getElementById("modal").style.display = "none";
        };
    });
</script>
</body>
</html> 